/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.tools;

import database.DatabaseConnection;
import gui.GUIWindow;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import tools.HexTool;

/**
 *
 * @author Administrator
 */
public class 野外BOSS刷新时间 extends javax.swing.JFrame {

    /**
     * Creates new form 锻造控制台
     */
    public 野外BOSS刷新时间() {
        ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("Image/Icon.png"));
        setIconImage(icon.getImage());
        setTitle("野外BOSS刷新时间控制台");
        initComponents();
    }



    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BOSS相关 = new javax.swing.JPanel();
        jScrollPane104 = new javax.swing.JScrollPane();
        野外BOSS刷新时间 = new javax.swing.JTable();
        刷新野外BOSS刷新时间 = new javax.swing.JButton();
        野外BOSS序号 = new javax.swing.JTextField();
        野外BOSS刷新时间值 = new javax.swing.JTextField();
        野外BOSS = new javax.swing.JTextField();
        刷新野外BOSS刷新时间修改 = new javax.swing.JButton();
        jLabel323 = new javax.swing.JLabel();
        jLabel324 = new javax.swing.JLabel();
        jLabel325 = new javax.swing.JLabel();

        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        BOSS相关.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "BOSS刷新时间", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("幼圆", 0, 24))); // NOI18N
        BOSS相关.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        野外BOSS刷新时间.setModel(new DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "序号", "野外BOSS", "刷新时间/分"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        野外BOSS刷新时间.getTableHeader().setReorderingAllowed(false);
        jScrollPane104.setViewportView(野外BOSS刷新时间);

        BOSS相关.add(jScrollPane104, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 30, 430, 390));

        刷新野外BOSS刷新时间.setFont(new java.awt.Font("幼圆", 0, 15)); // NOI18N
        刷新野外BOSS刷新时间.setText("刷新");
        刷新野外BOSS刷新时间.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                刷新野外BOSS刷新时间ActionPerformed(evt);
            }
        });
        BOSS相关.add(刷新野外BOSS刷新时间, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 180, 90, 30));

        野外BOSS序号.setEditable(false);
        BOSS相关.add(野外BOSS序号, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 100, 100, 30));
        BOSS相关.add(野外BOSS刷新时间值, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 100, 120, 30));

        野外BOSS.setEditable(false);
        BOSS相关.add(野外BOSS, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 100, 210, 30));

        刷新野外BOSS刷新时间修改.setFont(new java.awt.Font("幼圆", 0, 15)); // NOI18N
        刷新野外BOSS刷新时间修改.setText("修改");
        刷新野外BOSS刷新时间修改.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                刷新野外BOSS刷新时间修改ActionPerformed(evt);
            }
        });
        BOSS相关.add(刷新野外BOSS刷新时间修改, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 180, 90, 30));

        jLabel323.setFont(new java.awt.Font("幼圆", 0, 14)); // NOI18N
        jLabel323.setText("刷新时间；");
        BOSS相关.add(jLabel323, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 80, -1, -1));

        jLabel324.setFont(new java.awt.Font("幼圆", 0, 14)); // NOI18N
        jLabel324.setText("序号；");
        BOSS相关.add(jLabel324, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 80, -1, -1));

        jLabel325.setFont(new java.awt.Font("幼圆", 0, 14)); // NOI18N
        jLabel325.setText("BOSS；");
        BOSS相关.add(jLabel325, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 80, -1, -1));

        getContentPane().add(BOSS相关, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 920, 430));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void 刷新野外BOSS刷新时间ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_刷新野外BOSS刷新时间ActionPerformed
        刷新野外BOSS刷新时间();
    }//GEN-LAST:event_刷新野外BOSS刷新时间ActionPerformed
    public void 刷新野外BOSS刷新时间() {
        for (int i = ((DefaultTableModel) (this.野外BOSS刷新时间.getModel())).getRowCount() - 1; i >= 0; i--) {
            ((DefaultTableModel) (this.野外BOSS刷新时间.getModel())).removeRow(i);
        }
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = null;
            ResultSet rs = null;
            ps = con.prepareStatement("SELECT * FROM configvalues WHERE id >= 10000 && id < 20000");
            rs = ps.executeQuery();
            while (rs.next()) {
                ((DefaultTableModel) 野外BOSS刷新时间.getModel()).insertRow(野外BOSS刷新时间.getRowCount(), new Object[]{rs.getString("id"), rs.getString("name"), rs.getString("Val")});
            }
        } catch (SQLException ex) {
            Logger.getLogger(野外BOSS刷新时间.class.getName()).log(Level.SEVERE, null, ex);
        }
        野外BOSS刷新时间.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                int i = 野外BOSS刷新时间.getSelectedRow();
                String a = 野外BOSS刷新时间.getValueAt(i, 0).toString();
                String a1 = 野外BOSS刷新时间.getValueAt(i, 1).toString();
                String a2 = 野外BOSS刷新时间.getValueAt(i, 2).toString();
                野外BOSS序号.setText(a);
                野外BOSS.setText(a1);
                野外BOSS刷新时间值.setText(a2);
            }
        });
    }
    private void 刷新野外BOSS刷新时间修改ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_刷新野外BOSS刷新时间修改ActionPerformed
        PreparedStatement ps = null;
        PreparedStatement ps1 = null;
        ResultSet rs = null;
        boolean result1 = this.野外BOSS刷新时间值.getText().matches("[0-9]+");

        if (result1) {
            try {
                ps = DatabaseConnection.getConnection().prepareStatement("UPDATE configvalues SET Val = ? WHERE id = ?");

                ps1 = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM configvalues WHERE id = ?");

                ps1.setInt(1, Integer.parseInt(this.野外BOSS序号.getText()));
                rs = ps1.executeQuery();
                if (rs.next()) {
                    String sqlString1 = null;
                    sqlString1 = "update configvalues set Val = '" + this.野外BOSS刷新时间值.getText() + "' where id= " + this.野外BOSS序号.getText() + ";";
                    PreparedStatement Val = DatabaseConnection.getConnection().prepareStatement(sqlString1);
                    Val.executeUpdate(sqlString1);
                    刷新野外BOSS刷新时间();
                    server.Start.GetConfigValues();
                    JOptionPane.showMessageDialog(null, "修改成功，已经生效");
                }
            } catch (SQLException ex) {
                Logger.getLogger(野外BOSS刷新时间.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "请选择你要修改的刷新时间");
        }
    }//GEN-LAST:event_刷新野外BOSS刷新时间修改ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel BOSS相关;
    private javax.swing.JLabel jLabel323;
    private javax.swing.JLabel jLabel324;
    private javax.swing.JLabel jLabel325;
    private javax.swing.JScrollPane jScrollPane104;
    private javax.swing.JButton 刷新野外BOSS刷新时间;
    private javax.swing.JButton 刷新野外BOSS刷新时间修改;
    private javax.swing.JTextField 野外BOSS;
    private javax.swing.JTable 野外BOSS刷新时间;
    private javax.swing.JTextField 野外BOSS刷新时间值;
    private javax.swing.JTextField 野外BOSS序号;
    // End of variables declaration//GEN-END:variables
}
